// Zepto
var $ = require('./components/zepto/zepto');
require('./components/zepto/event');
require('./components/zepto/ajax');
require('./components/zepto/form');
require('./components/zepto/ie');
require('./components/zepto/touch');

module.exports = $;

// 引入Swiper
var Swiper = require('./components/swiper/swiper.min.js');
var swiperAnimate = require('./components/swiper/swiper.animate1.0.2.min.js');
var swiper = new Swiper ('.swiper-container', {
	pagination: '.swiper-pagination',
    paginationClickable: true,
  onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
    swiperAnimate.swiperAnimateCache(swiper); //隐藏动画元素 
    swiperAnimate.swiperAnimate(swiper); //初始化完成开始动画
  }, 
  onSlideChangeEnd: function(swiper){ 
    swiperAnimate.swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
  } 
}) 

var myScroll;
function loaded(){
    if($('.iScrollVerticalScrollbar')){
        $('.iScrollVerticalScrollbar').remove();
    }
    myScroll = new IScroll('#wrapper', {
        scrollbars: true,
        mouseWheel: true,
        interactiveScrollbars: true,
        shrinkScrollbars: 'scale',
        fadeScrollbars: true
    });
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, isPassive() ? {
	capture: false,
	passive: false
} : false); 
}

 $("#mainContainer").hide();
 $(".swiper-container").hide();
// jquery/zepto
$("#enter").tap(function(){
    $(".swiper-container").hide();
    $("#mainContainer").show();

    $.ajax({
        async:false,
        type:'GET',
        url:'./../api/work.php',
        dataType:'json',
        success:function(data){
            var html = "";
            for(var i=0;i<data.length;i++){
                html +='<li class="animated slideInUp">'+ 
                '<div class="img">'+data[i].category+'</div>'+
                '<div class="image"><img src="images/work'+(i+1)+'.png" alt=""></div>'+
                '<div>'+
                '<p><span>公司名称</span>：'+data[i].name+'</p>'+
                '<p><span>网    址</span>：'+data[i].url+'</p>'+
                '<p><span>年    限</span>：'+data[i].time+'</p>'+
                '<p><span>职    称</span>：'+data[i].posts+'</p>'+
                '<p><span>级    别</span>：'+data[i].reportto+'</p>'+
                '<p><span>成    员</span>：'+data[i].peoples+'</p>'+
                '<p><span>项    目</span>：'+data[i].projects+'</p>'+
                '</div>'+
                "</li>";
            }
            $("#scroller ul").html(html);
        }
    })
    loaded();
})


$("#footer ul li").tap(function(){
    var apiTarget = $(this).attr('id');
    var apiUrl = "./../api/" + apiTarget + ".php";
    $(this).css({'color':'green'}).children('i').css({'color':'green'});
    $(this).siblings().css({'color':'gray'}).children('i').css({'color':'gray'});
    $('.tpname').html($(this).text());

    if(apiTarget=='skill'){
        $.ajax({
            async:false,
            type:'GET',
            url:apiUrl,
            dataType:'json',
            success:function(data){
                var html = '';
                for(var i=0;i<data.length;i++){
                    html +='<li class="animated zoomIn">'+ 
                    '<div class="img">'+data[i].category+'</div>'+
                    '<div>'+
                    '<p><span>技    能</span>：'+data[i].name+'</p>'+
                    '<p><span>年    限</span>：'+data[i].time+'</p>'+
                    '<p><span>程    度</span>：'+data[i].level+'</p>'+
                    '</div>'+
                    "</li>";
                }
                $("#scroller ul").html(html);   
            }
        })
        loaded();
    }else if(apiTarget=='project'){
        $.ajax({
            async:false,
            type:'GET',
            url:apiUrl,
            dataType:'json',
            success:function(data){
                var html = '';   
                for(var i=0;i<data.length;i++){
                    html +='<li class="animated flipInX">'+  
                    '<div class="img">'+data[i].category+'</div>'+
                    '<div class="image"><img src="images/project'+(i+1)+'.png" alt=""></div>'+
                    '<div>'+
                    '<p><span>公司名称</span>：'+data[i].name+'</p>'+
                    '<p><span>网    址</span>：'+data[i].url+'</p>'+
                    '<p><span>简    介</span>：'+data[i].description+'</p>'+
                    '<p><span>详    情</span>：'+data[i].detail+'</p>'+
                    '<p><span>运    用</span>：'+data[i].tech+'</p>'+
                    '</div>'+
                    "</li>";
                }
                $("#scroller ul").html(html);   
            }
        })
        loaded();
    }else if(apiTarget=='work'){
        $.ajax({
            async:false,
            type:'GET',
            url:apiUrl,
            dataType:'json',
            success:function(data){
                var html = ''; 
                for(var i=0;i<data.length;i++){
                    html +='<li class="animated slideInUp">'+  
                    '<div class="img">'+data[i].category+'</div>'+
                    '<div class="image"><img src="images/work'+(i+1)+'.png" alt=""></div>'+
                    '<div>'+
                    '<p><span>公司名称</span>：'+data[i].name+'</p>'+
                    '<p><span>网    址</span>：'+data[i].url+'</p>'+
                    '<p><span>年    限</span>：'+data[i].time+'</p>'+
                    '<p><span>职    称</span>：'+data[i].posts+'</p>'+
                    '<p><span>级    别</span>：'+data[i].reportto+'</p>'+
                    '<p><span>成    员</span>：'+data[i].peoples+'</p>'+
                    '<p><span>项    目</span>：'+data[i].projects+'</p>'+
                    '</div>'+
                    "</li>";
                }
                $("#scroller ul").html(html);   
            }
        })
        loaded();
    }else if(apiTarget=='me'){
        $.ajax({
            async:false,
            type:'GET',
            url:apiUrl,
            dataType:'json',
            success:function(data){
                var html = '';
                for(var i=0;i<data.length;i++){
                    html +='<li>'+              
                    '<div class="img">'+data[i].category+'</div>'+
                    '<div class="image1"><img src="images/me.jpg" alt=""></div>'+
                    '<div>'+
                    '<p><span>名    称</span>：'+data[i].name+'</p>'+
                    '<p><span>年    限</span>：'+data[i].time+'</p>'+
                    '<p><span>程    度</span>：'+data[i].level+'</p>'+
                    '<p><span>简    介</span>：'+data[i].title+'</p>'+
                    '</div>'+
                    "</li>";
                }
                $("#scroller ul").html(html);   
            }
        })
        loaded();
    }      
})

var interval  = setInterval(function(){
    if(document.readyState === 'complete'){
        clearInterval(interval);
        $("#loading").hide();
        $(".swiper-container").show();
        swiper.updateContainerSize(); // 万分重要
        swiper.updateSlidesSize(); // 万分重要
    }else{
        $("#loading").show();
    }
})

function isPassive() {
    var supportsPassiveOption = false;
    try {
        addEventListener("test", null, Object.defineProperty({}, 'passive', {
            get: function () {
                supportsPassiveOption = true;
            }
        }));
    } catch(e) {}
    return supportsPassiveOption;
}

